// pages/duobao/cjRec/cjRec.js
import S_request from '../../../utils/requestService.js';
import CONFIG from '../../../config.js';
import * as utils from '../../../utils/util.js';
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    menuList: [{
      id: '1',
      name: "待开奖",
      hidden: false,
      style: 'color:#fff;background-color:#ec0504;border:0;',
      
    },
    {
      id: '2',
      name: "已开奖",
      hidden: true,
      style: 'color:#999;border:1px solid #bababa;background-color: rgba(255, 255, 255, 0);'
    }
    ],
    swiperCurrent: 0, //当前的位置
    cjList: [],
    cjData: {},
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.getCJRecord();
  },
  getCJRecord: function () {
    S_request.mine.cjRecord((result) => {
      for (let i = 0; i < result.wait.length; i++) {
        let item = result.wait[i];
        item.open_time = utils.formatTime(item.open_time, 3);
        //pay_status表示类型 0：系统随机 1：分享最多者获得
        if (item.pay_status == 0) {
          item.txt = '系统随机抽取'
        } else {
          item.txt = '邀请最多者获得'
        }
        item.btnTitle = '待开奖'
        item.btnStyle = 'background-color:#0f9134;'
      }
      for (let i = 0; i < result.already.length; i++) {
        let item = result.already[i];
        item.open_time = utils.formatTime(item.open_time, 3);
        //pay_status表示类型 0：系统随机 1：分享最多者获得
        if (item.pay_status == 0) {
          item.txt = '系统随机抽取'
        } else {
          item.txt = '邀请最多者获得'
        }
        item.btnTitle = '已开奖'
        item.btnStyle = 'background-color:#9a9898;'
      }
      this.setData({
        cjData: result,
        cjList: result.wait
      })
    })
  },
  clickMenu: function (e) {
    let id = e.currentTarget.dataset.id;
    console.log(e.currentTarget.dataset.id);
    for (var i = 0; i < this.data.menuList.length; i++) {
      this.data.menuList[i]["hidden"] = true;
      this.data.menuList[i]["style"] = 'color:#999;border:1px solid #bababa;background-color: rgba(255, 255, 255, 0);';
    }
    this.data.menuList[id - 1]["hidden"] = false;
    this.data.menuList[id - 1]["style"] = 'color:#fff;background-color:#ec0504;border:0;';
    this.data.swiperCurrent = id - 1;
    let tempList = [];
    if (id == 1) {
      tempList = this.data.cjData.wait;
    } else {
      tempList = this.data.cjData.already;
    }
    this.setData({
      menuList: this.data.menuList,
      swiperCurrent: this.data.swiperCurrent,
      cjList: tempList
    })
  },
  changeCurrent: function (e) {
    let current = e.detail.current;
    console.log("aaaa==" + e.detail.current);
    
    for (var i = 0; i < this.data.menuList.length; i++) {
      this.data.menuList[i]["hidden"] = true;
      this.data.menuList[i]["color"] = 'color:#999;border:1px solid #bababa;background-color: rgba(255, 255, 255, 0);';
    }
    this.data.menuList[current]["hidden"] = false;
    this.data.menuList[current]["color"] = 'color:#fff;background-color:#ec0504;border:0;';
    let tempList = [];
    if (current == 0) {
      tempList = this.data.cjData.wait;
    } else {
      tempList = this.data.cjData.already;
    }
    this.setData({
      menuList: this.data.menuList,
      cjList: tempList
    })
  },
  toDetail: function (e) {
    let id = e.currentTarget.dataset.id;
    wx.navigateTo({
      url: '../../JX/detail/detail?id=' + id,
    })
    console.log("detail id==" + id)
  },
  //暂时不用
  chakan: function () {
    let id = e.currentTarget.dataset.id;
    let isKj = e.currentTarget.dataset.status0;
    let kjStatus = e.currentTarget.dataset.status;
    if (isKj == 0) { //等待开奖
      wx.navigateTo({
        url: '../detail/detail?id=' + id,
      })
    } else { //已开奖
    }
  },
  //触摸变小动画
  setShrink: function (e) {
    this.setData({
      id: e.currentTarget.dataset.id,
    });
    let animation1 = wx.createAnimation({
      transformOrigin: "50% 50%",
      duration: 200,
      timingFunction: "ease"
    });
    animation1.scale(0.95).step();
    this.setData({
      animation1: animation1.export()
    });
  },
  //手指离开放大动画
  remShrink: function (e) {
    this.setData({
      id: e.currentTarget.dataset.id,
    });
    let animation1 = wx.createAnimation({
      transformOrigin: "50% 50%",
      duration: 200,
      timingFunction: "ease"
    });
    animation1.scale(1.0).step();
    this.setData({
      animation1: animation1.export()
    });
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    // this.getCJRecord();
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
    wx.showShareMenu({
      withShareTicket: false,
      success: function () { }
    });
    let obj = { 'pagepath': CONFIG.SHARE.path }
    S_request.jx.recordShare("-1", obj);
    return {
      title: CONFIG.SHARE.title,
      path: CONFIG.SHARE.path,
      imageUrl: CONFIG.SHARE.imageUrl,
      success: (res) => { //新版不走回调
        console.log("分享成功")
      }
    }
  },
})